<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form v-loading="formLoading" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="180px">
    <el-form-item label="水泵名称" prop="name">
      <el-input v-model="dataForm.name" placeholder="水泵名称"></el-input>
    </el-form-item>

    <el-form-item label="出水量" prop="name">
      <el-input v-model="dataForm.waterl" placeholder="水泵名称"></el-input>
    </el-form-item>
   
    <el-form-item label="开关状态（绑定灯位）" prop="switchn">
      <!-- <el-input v-model="dataForm.switchn" placeholder="开关状态"></el-input> -->
      <el-select v-model="dataForm.switchn" filterable placeholder="请选择" style="width:100%">
            <el-option value="">请选择</el-option>
              <el-option
              v-for="item in ztoption"
              :key="item.value"
              :label="item.label"
              :value="item.value">
              </el-option>
          </el-select>
    </el-form-item>
    <el-form-item label="水泵状态（绑定灯位）" prop="pumn">
      <!-- <el-input v-model="dataForm.pumn" placeholder="水泵状态"></el-input> -->
      <el-select v-model="dataForm.pumn" filterable placeholder="请选择" style="width:100%">
            <el-option value="">请选择</el-option>
              <el-option
              v-for="item in ztoption"
              :key="item.value"
              :label="item.label"
              :value="item.value">
              </el-option>
          </el-select>
    </el-form-item>

 
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-loading="formLoading" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        formLoading: false,
        dataForm: {
          id: 0,
          name: '',
          switchb: '',
          pumstatu: '',
          switchn: '',
          waterl:'',
          pumn: '',
          createId: '',
          createName: '',
          createTime: '',
          updateId: '',
          updateTime: '',
          updateName: '',
          version: '',
          gcFlag: ''
        },
         ztoption: [{
          value: Number('1'),
          label: '1'
        }, {
          value: Number('2'),
          label: ' 2'
        }, {
          value: Number('3'),
          label: ' 3'
        }, {
          value: Number('4'),
          label: ' 4'
        }, {
          value: Number('5'),
          label: ' 5'
        }, {
          value: Number('6'),
          label: ' 6'
        }, {
          value: Number('7'),
          label: ' 7'
        }, {
          value: Number('8'),
          label: ' 8'
        }, {
          value: Number('9'),
          label: ' 9'
        }, {
          value: Number('10'),
          label: ' 10'
        }, {
          value: Number('11'),
          label: ' 11'
        }, {
          value: Number('12'),
          label: ' 12'
        }, {
          value: Number('13'),
          label: ' 13'
        }, {
          value: Number('14'),
          label: ' 14'
        }, {
          value: Number('15'),
          label: ' 15'
        }, {
          value: Number('16'),
          label: ' 16'
        }, {
          value: Number('17'),
          label: ' 17'
        }, {
          value: Number('18'),
          label: ' 18'
        }, {
          value: Number('19'),
          label: ' 19'
        }, {
          value: Number('20'),
          label: ' 20'
        }],
        dataRule: {
          name: [
            { required: true, message: '水泵名称不能为空', trigger: 'blur' }
          ],
          switchb: [
            { required: true, message: '对应开关不能为空', trigger: 'blur' }
          ],
          pumstatu: [
            { required: true, message: '对应状态灯不能为空', trigger: 'blur' }
          ],
          switchn: [
            { required: true, message: '开关状态不能为空', trigger: 'blur' }
          ],
          pumn: [
            { required: true, message: '水泵状态不能为空', trigger: 'blur' }
          ],

        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/buss/busswaterpum/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                console.log(data);
                this.dataForm.name = data.bussWaterpum.name
                //this.dataForm.switchb = data.busswaterpum.switchb
                //this.dataForm.pumstatu = data.busswaterpum.pumstatu
                this.dataForm.switchn = data.bussWaterpum.switchn
                this.dataForm.waterl = data.bussWaterpum.waterl
                this.dataForm.pumn = data.bussWaterpum.pumn
                this.dataForm.createId = data.bussWaterpum.createId
                this.dataForm.createName = data.bussWaterpum.createName
                this.dataForm.createTime = data.bussWaterpum.createTime
                this.dataForm.updateId = data.bussWaterpum.updateId
                this.dataForm.updateTime = data.bussWaterpum.updateTime
                this.dataForm.updateName = data.bussWaterpum.updateName
                this.dataForm.version = data.bussWaterpum.version
                this.dataForm.gcFlag = data.bussWaterpum.gcFlag
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid && !this.formLoading) {
            this.formLoading = true
            this.$http({
              url: this.$http.adornUrl(`/buss/busswaterpum/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'name': this.dataForm.name,
                'switchb': this.dataForm.switchb,
                'pumstatu': this.dataForm.pumstatu,
                'switchn': this.dataForm.switchn,
                'waterl': this.dataForm.waterl,
                'pumn': this.dataForm.pumn,
                'createId': this.dataForm.createId,
                'createName': this.dataForm.createName,
                'createTime': this.dataForm.createTime,
                'updateId': this.dataForm.updateId,
                'updateTime': this.dataForm.updateTime,
                'updateName': this.dataForm.updateName,
                'version': this.dataForm.version,
                'gcFlag': this.dataForm.gcFlag
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.formLoading = false
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
